package com.example.demo.design.template_method.salary_deliver;

import java.time.LocalDateTime;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 17:40 2020/11/14
 * @Modified By:
 */
public class SalariedEmployee extends Employee {
    private final double monthlySalary;

    public SalariedEmployee(double monthlySalary, String name, int number, MyDate birth) {
        super(name, number, birth);
        this.monthlySalary = monthlySalary;
    }

    @Override
    public double earnings() {
        double salary = monthlySalary;
        if (isBirthday()) {
            salary += 100;
        }
        return salary;
    }

    public boolean isBirthday() {
        LocalDateTime now = LocalDateTime.now();
        return getBirthday().getYear() == now.getYear() &&
                getBirthday().getMonth() == now.getMonth().getValue() &&
                getBirthday().getDay() == now.getDayOfMonth();
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + super.toString();
    }
}
